package e.odbo.data.generator;

import java.util.Random;

public class RoundStringGenerator extends Generator<String>{

    protected String str="zxcvbnmlkjhgfdsaqwertyuiopQWERTYUIOPASDFGHJKLZXCVBNM1234567890";
    public final static String SYMBOL ="_-=[]/~!@#$%^&*()_+|{}:<>?";
    protected int lineLength;

    public RoundStringGenerator(int lineLength) {
        this.lineLength = lineLength;
    }

    public RoundStringGenerator(int lineLength,boolean symbol) {
        this.lineLength = lineLength;
        if(symbol)
           str=str+SYMBOL;
    }

    public RoundStringGenerator(int lineLength,String advString,boolean symbol) {
        this.lineLength = lineLength;
        if(null!=advString)
           str=str+advString;
        if(symbol)
            str=str+SYMBOL;
    }

    public RoundStringGenerator(int lineLength,String advString) {
        this(lineLength,advString,false);
    }

    @Override
    public String generator() {
        Random random=new Random();
        StringBuffer sb=new StringBuffer();
        //长度为几就循环几次
        for(int i=0; i<lineLength; ++i){
            //产生0-61的数字
            int number=random.nextInt(str.length());
            //将产生的数字通过length次承载到sb中
            sb.append(str.charAt(number));
        }
        //将承载的字符转换成字符串
        return sb.toString();
    }

    @Override
    public String getName() {
        return "RoundString:"+lineLength;
    }
}
